<!DOCTYPE HTML>
<html  lang="zh" xmlns:th="http://www.thymeleaf.org">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<link th:href="@{/css/jquery.editable-select.css}" rel="stylesheet"/>

<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-bizTable-edit" th:object="${bizTable}" autocomplete="off">
            <div class="form-group hidden">	
                <label class="col-sm-2 control-label">生成策略：</label>
                <div class="col-sm-8">
                    <input id="genType" name="genType" th:field="*{genType}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group hidden">	
                <label class="col-sm-2 control-label">父表名称：</label>
                <div class="col-sm-8">
                    <input id="parentName" name="parentName" th:field="*{parentName}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group ">	
                <label class="col-sm-2 control-label"><span class="red">*</span>表名称：</label>
                <div class="col-sm-3">
                    <input id="name" name="name" th:field="*{name}" class="form-control" type="text" readOnly required>
                    <input id="state" name="state" th:field="*{state}" type="hidden" >
                </div>
               
            </div>
            
            <div class="form-group">
             	<label class="col-sm-2 control-label"><span class="red">*</span>表注释：</label>
                <div class="col-sm-3">
                    <input id="comments" name="comments" th:field="*{comments}" class="form-control" type="text" required>
                </div>
                <label class="col-sm-2 control-label"><span class="red">*</span>实体名称：</label>
                <div class="col-sm-3">
                    <input id="entityName" name="entityName" th:field="*{entityName}" class="form-control" type="text" required>
                </div>
            </div>
            
            <div class="form-group">
                <label class="col-sm-2 control-label"><span class="red">*</span>生成包名：</label>
                <div class="col-sm-3">
                    <input id="packageName" name="packageName" th:field="*{packageName}" class="form-control" type="text" required>
                </div>
                <label class="col-sm-2 control-label"><span class="red">*</span>作者：</label>
                <div class="col-sm-3">
                    <input id="author" name="author" th:field="*{author}" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">
            	
                <label class="col-sm-2 control-label"><span class="red">*</span>主键类型：</label>
                <div class="col-sm-3">
                    <label class="radio-box"><input type="radio" th:field="*{idCata}" value="1" id="idCata1" name="idCata">自增</label>
                    <label class="radio-box"><input type="radio" value="2" th:field="*{idCata}" id="idCata2" name="idCata">字符串</label>
                </div>
                
                <label class="col-sm-2 control-label"><span class="red">*</span>是否支持导入：</label>
                <div class="col-sm-3">
                    <label class="radio-box"><input type="radio" th:field="*{isImport}" value="1" id="isImport1" name="isImport">是</label>
                    <label class="radio-box"><input type="radio" value="0" th:field="*{isImport}" id="isImport2" name="isImport">否</label>
                </div>
            	
            </div>
            
            <div class="form-group">
	            <div class="col-sm-12">
	                <div class="ibox float-e-margins">
	                    <div class="ibox-title">
	                        <h5 class="ibox-title-h5 activite"><a href="javascript:;">字段信息</a></h5>
	                        <h5 class="ibox-title-h5 " style="margin-left: 5px;"><a href="javascript:editCol_Extend();">拓展信息</a></h5>
	                        <div class="ibox-tools">
	                            <a class="collapse-link">
	                                <i class="fa fa-chevron-up"></i>
	                            </a>
	                            <a class="dropdown-toggle  add-column-item"  href="javascript:;">
	                                <i class="fa fa-plus"></i>
	                            </a>
	                        </div>
	                    </div>
	                    <div class="ibox-content" style="padding:  0px 0px 0px">
	                        <table class="table table-bordered data-tr">
	                            <thead>
	                                <tr>
	                                    <th style="width: 10%;">字段名称</th>
	                                    <th style="width: 10%;">字段备注</th>
	                                    <th style="width: 10%;">字段类型</th>
	                                    <th style="width: 5%;">长度</th>
	                                    <th style="width: 10%;">属性类型</th>
	                                    <th style="width: 10%;">属性名称</th>
	                                    <th  style="width: 4%;" title="字段是否是主键字段">主键</th>
	                                    <th style="width: 5%;">顺序</th>
	                                    <th>操作</th>
	                                </tr>
	                            </thead>
	                            <tbody>
	                            	<tr th:each="colItem,colStat:${colsList}" >
	                            		<td>
	                            			<input th:name="${'cloumn['+colStat.index+'].name'}" class="form-control column_name" type="text" th:value="${colItem.name}" required>
	                            			<input type="hidden" th:name="${'cloumn['+colStat.index+'].id'}" th:value="${colItem.id}"/>
	                            			<input type="hidden" th:name="${'cloumn['+colStat.index+'].isNull'}" th:value="${colItem.isNull}"/>
	                            			<input type="hidden" th:name="${'cloumn['+colStat.index+'].isInsert'}" th:value="${colItem.isInsert}"/>
	                            			<input type="hidden" th:name="${'cloumn['+colStat.index+'].isEdit'}" th:value="${colItem.isEdit}"/>
	                            			<input type="hidden" th:name="${'cloumn['+colStat.index+'].isList'}" th:value="${colItem.isList}"/>
	                            			<input type="hidden" th:name="${'cloumn['+colStat.index+'].isImport'}" th:value="${colItem.isImport}"/>
	                            			<input type="hidden" th:name="${'cloumn['+colStat.index+'].isQuery'}" th:value="${colItem.isQuery}"/>
	                            		</td>
	                                    <td><input th:name="${'cloumn['+colStat.index+'].comments'}" class="form-control " type="text" required th:value="${colItem.comments}"></td>
	                                    <td style="position: relative;">
		                                    <select th:name="${'cloumn['+colStat.index+'].jdbcType'}" class="form-control editable_select jdbc_type" required th:value="${colItem.jdbcType}">
		                                    	<option value="">--请选择--</option>
	               								<option value="bigint(18)" >bigint(18)</option>
												<option value="varchar(32)" >varchar(32)</option>
												<option value="varchar(64)" >varchar(64)</option>
												<option value="int(11)" >int(11)</option>
												<option value="double(10)" >double(10)</option>
												<option value="decimal(10,2)" >decimal(10,2)</option>
												<option value="datetime" >datetime</option>
												<option value="text" >text</option>
												<option value="longtext" >longtext</option>
		                                    </select>
	                                    </td>
	                                    <td><input th:name="${'cloumn['+colStat.index+'].jdbcLength'}" class="form-control jdbcLen" type="text"  th:value="${colItem.jdbcLength}"></td>
	                                    <td>
	                                    	<select th:name="${'cloumn['+colStat.index+'].javaType'}" class="form-control attr_type" required>
	                                    		<option value="">--请选择--</option>
                 								<option value="String"  th:selected="${colItem.javaType=='String'}">String</option>
												<option value="Long"   th:selected="${colItem.javaType=='Long'}">Long</option>
												<option value="Integer"  th:selected="${colItem.javaType=='Integer'}">Integer</option>
												<option value="Double"  th:selected="${colItem.javaType=='Double'}">Double</option>
												<option value="Date"    th:selected="${colItem.javaType=='Date'}">Date</option>
	                                    	</select>
	                                    </td>
	                                    <td><input th:name="${'cloumn['+colStat.index+'].javaField'}" class="form-control attr_name" type="text" required th:value="${colItem.javaField}"></td>
	                                    <td><label class="check-box table-check-box-center"><input th:name="${'cloumn['+colStat.index+'].isPk'}" type="checkbox" value="1" th:checked="${colItem.isPk=='1'}"></label></td>
	                                    
	                                    <td><input th:name="${'cloumn['+colStat.index+'].sort'}" class="form-control table-form-control_w_50" type="text" value="1" required th:value="${colItem.sort}"></td>
	                                    <td>
	                                    	<a th:if="${colStat.index == 0}" href="javascript:;" class="add-column-item">新增</a>
	                                    	<a th:if="${colStat.index > 0 }" href="javascript:;" th:onclick="${'delColumn('+colItem.id+')'}">删除</a>
	                                    </td>
	                            	</tr>
	                                <tr th:if="${#lists.size(colsList) == 0}">
	                                    <td><input name="cloumn[0].name" class="form-control column_name" type="text" required></td>
	                                    <td><input name="cloumn[0].comments" class="form-control " type="text" required></td>
	                                    <td style="position: relative;">
		                                    <select name="cloumn[0].jdbcType" class="form-control editable_select jdbc_type" required>
		                                    	<option value="">--请选择--</option>
	               								<option value="bigint(18)" >bigint(18)</option>
												<option value="varchar(32)" >varchar(32)</option>
												<option value="varchar(64)" >varchar(64)</option>
												<option value="int(11)" >int(11)</option>
												<option value="double(10)" >double(10)</option>
												<option value="decimal(10,2)" >decimal(10,2)</option>
												<option value="datetime" >datetime</option>
												<option value="text" >text</option>
												<option value="longtext" >longtext</option>
		                                    </select>
	                                    </td>
	                                    <td><input name="cloumn[0].jdbcLength" class="form-control jdbcLen" type="text" ></td>
	                                    <td>
	                                    	<select name="cloumn[0].javaType" class="form-control attr_type" required>
	                                    		<option value="">--请选择--</option>
                 								<option value="String" >String</option>
												<option value="Long"  >Long</option>
												<option value="Integer" >Integer</option>
												<option value="Double" >Double</option>
												<option value="Date"   >Date</option>
	                                    	</select>
	                                    </td>
	                                    <td><input name="cloumn[0].javaField" class="form-control attr_name" type="text" required></td>
	                                    <td><label class="check-box table-check-box-center"><input name="cloumn[0].isPk" type="checkbox" value="1"></label></td>
	                                    
	                                    <td><input name="cloumn[0].sort" class="form-control table-form-control_w_50" type="text" value="1" required></td>
	                                    <td>
	                                    	<a href="javascript:;" class="add-column-item">新增</a>
	                                    </td>
	                                </tr>
	                               
	                            </tbody>
	                        </table>
	
	                    </div>
	                </div>
	                
	                
	            </div>
            </div>
            <div class="form-group">
            <div class="form-control-static col-sm-offset-10 buttonleft">
                <button type="button" class="btn btn-primary" onclick="submitHandler();">提交</button>
                <button onclick="close_this_tab()" class="btn btn-danger" type="button">关闭</button>
            </div>
        </div>
        
		</form>
    </div>
    <div th:include="include::footer"></div>
	<script type="text/javascript" src="/ajax/libs/jquery.editable-select.js"></script>
    <script type="text/javascript" src="/svs/scripts/views-editable-select.js"></script>
    <script type="text/javascript" src="/svs/scripts/views-table_biz-column.js"></script>
    <script type="text/javascript">
		var prefix = ctx + "project/bizTable"
		EditableSelectView.init() ;
		function submitHandler() {
	        if ($.validate.form()) {
	        	$.modal.loading("正在处理中，请稍后...");
	        	var config = {
        	        url: prefix + "/edit",
        	        type: "post",
        	        dataType: "json",
        	        data: $('#form-bizTable-edit').serialize(),
        	        success: function(result) {
        	        	$.modal.msgSuccess('保存成功...........');
        	        	$.modal.closeLoading() ;
        	        	$.modal.refreshTab() ;
        	        }
        	    };
        	    $.ajax(config)
	        }
	    }
		
		function close_this_tab() {
			parent.$('.page-tabs-content').find('.active i').trigger("click");
		}
		
		function editCol_Extend() {
			var id = '[[${bizTable.name}]]' ;
			var url = prefix + "/editCol_Extend/"+id ;
			var currentId = parent.$('.page-tabs-content').find('.active').attr('data-id');
        	var target = parent.$('.Svs_iframe[data-id="' + currentId + '"]');
        	target.attr('data-id',url) ;
        	parent.$('.page-tabs-content').find('.active').attr('data-id',url) ;
            target.attr('src', url).ready();
            
			$.modal.refreshTab() ;
		}
		
		function delColumn(id) {
        	$.modal.confirm("确定删除表字段吗？", function() {
        		$.modal.loading("正在处理中，请稍后...");
        		var url = prefix + '/delColumn?id='+id ;
            	var config = {
        	        url: url,
        	        type: 'post',
        	        dataType: 'json',
        	        data: {},
        	        success: function(result) {
        	        	$.modal.msgSuccess('同步成功...........');
        	        	$.modal.closeLoading() ;
        	        	$.modal.refreshTab() ;
        	        }
        	    };
        	    $.ajax(config)
        	})
        }
		
	</script>
</body>
</html>
